const Router = require("koa-router"); //1 导入包

const { register, login } = require("../controller/user.controller");
const {
  userValidator,
  verifyUser,
  cryptPaasword,
  verifyLogin,
} = require("../middleware/user.middleware");

const { authToken } = require("../middleware/auth.middleware");

const router = new Router({ prefix: "/users" }); //2实例化对象   prefix是在该路由前面拼接上该前缀

//注册接口
router.post("/register", userValidator, verifyUser, cryptPaasword, register);

//登录
router.post("/login", userValidator, verifyLogin, login);

//修改密码
router.post("/modify", authToken, cryptPaasword, (ctx, next) => {
  console.log(ctx.state.user);
  ctx.body = "修改成功";
});

module.exports = router; //一定要记得导出
